package com.group.eams.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.group.eams.pojo.dto.OpusCategoryQueryDto;
import com.group.eams.pojo.entity.OpusCategory;
import com.group.eams.service.OpusCategoryService;
import com.group.eams.mapper.OpusCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 恩哲欣
* @description 针对表【opus_category(作品分类表)】的数据库操作Service实现
* @createDate 2024-10-29 16:09:34
*/
@Service
public class OpusCategoryServiceImpl extends ServiceImpl<OpusCategoryMapper, OpusCategory> implements OpusCategoryService{

    @Autowired
    private OpusCategoryMapper opusCategoryMapper;
    /**
     * 根据查询条件查询作品分类
     *
     * @param opusCategoryQueryDto 查询条件
     * @return 分页结果
     */
    @Override
    public Page<OpusCategory> findByQueryDto(OpusCategoryQueryDto opusCategoryQueryDto) {
        Page<OpusCategory> page = new Page<>(opusCategoryQueryDto.getPage(), opusCategoryQueryDto.getLimit());
        LambdaQueryWrapper<OpusCategory> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper
                .like(!StrUtil.isEmpty(opusCategoryQueryDto.getName()), OpusCategory::getName, opusCategoryQueryDto.getName())
                .like(!StrUtil.isEmpty(opusCategoryQueryDto.getName()), OpusCategory::getName, opusCategoryQueryDto.getName())
                .eq(opusCategoryQueryDto.getStatus() != null, OpusCategory::getStatus, opusCategoryQueryDto.getStatus());
        return opusCategoryMapper.selectPage(page, queryWrapper);
    }
}
